<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>GETphp试验</title>
</head>
<body>
    <form>
        <input type="text" name="username" id="inp1">
        <input type="submit" id="sub">
    </form>
    <p></p>
</body>

<script>
    var sub = document.getElementById("sub");
    sub.addEventListener("click",function (e) {
        e.preventDefault();
        var xmlHttp = new XMLHttpRequest();

        var inp1 = document.getElementById("inp1");
        
        xmlHttp.open("GET","a.php?username="+inp1.value,true);
        xmlHttp.send()

        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                document.getElementsByTagName("p")[0].innerHTML = xmlHttp.responseText;

            }
        }
    })
</script>
</html>